package com.eliteams.quick4j.web.interceptors.client;

import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.springframework.stereotype.Service;

import com.eliteams.quick4j.web.interceptors.VisitorsClient;

@Service
public class VisitorsClientImpl implements VisitorsClient {

	@Override
	public String queryVisitors(String token, String userId) {
		JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
		String wsUrl = "http://sync.yd-jxt.com/Sync2/DingWebService.asmx?WSDL";
		String method = "TVisitSign";
		Client client = dcf.createClient(wsUrl);
		Object[] res = null;
		try {
			res = client.invoke(method, token,userId);
		} catch (Exception e) {
			e.printStackTrace();
		}
		if (res != null && res.length > 0) {
			return res[0].toString();
		}
		return null;
	}

	@Override
	public String getVisitor(String token,long id) {
		JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
		String wsUrl = "http://sync.yd-jxt.com/Sync2/DingWebService.asmx?WSDL";
		String method = "TVisitSign_info";
		Client client = dcf.createClient(wsUrl);
		Object[] res = null;
		try {
			res = client.invoke(method,token, id);
		} catch (Exception e) {
			e.printStackTrace();
		}
		if (res != null && res.length > 0) {
			return res[0].toString();
		}
		return null;
	}
	
	@Override
	public String setVisitorRet(String token,long id,int ret) {
		JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
		String wsUrl = "http://sync.yd-jxt.com/Sync2/DingWebService.asmx?WSDL";
		String method = "TVisitSign_info_ret";
		Client client = dcf.createClient(wsUrl);
		Object[] res = null;
		try {
			res = client.invoke(method,token, id,ret);
		} catch (Exception e) {
			e.printStackTrace();
		}
		if (res != null && res.length > 0) {
			return res[0].toString();
		}
		return null;
	}
	
	

	
}
